package com.zyit.service;

import com.zyit.service.Impl.GoodsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/myUpload")
public class MyUploadService extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取前端传来的参数
        String selectone = req.getParameter("selectone");
        String selecttwo = req.getParameter("selecttwo");
        String classifyLevel3 = req.getParameter("classifyLevel3");
        String goodsName = req.getParameter("goodsName");
        String price = req.getParameter("price");
        String stock = req.getParameter("stock");
        String goods_desc = req.getParameter("goods_desc");
        String file = req.getParameter("file");

        // 在这里，您可以执行任何与这些参数相关的服务器端逻辑，比如将它们存入数据库
        // 示例：将参数打印到控制台
        System.out.println("selectone: " + selectone);
        System.out.println("selecttwo: " + selecttwo);
        System.out.println("classifyLevel3: " + classifyLevel3);
        System.out.println("goodsName: " + goodsName);
        System.out.println("price: " + price);
        System.out.println("stock: " + stock);
        System.out.println("goods_desc: " + goods_desc);
        System.out.println("file: " + file);

        // 在这里，您可以执行数据库操作、验证等其他逻辑
        GoodsService goodsService = new GoodsServiceImpl();
        try {
            int i = goodsService.InsertGoods(goodsName, price, stock, selectone, selecttwo, classifyLevel3, goods_desc, file);

            if (i == 1) {
                resp.getWriter().write("true");
            } else {
                resp.getWriter().write("false");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}

